import { Effect, ImmerReducer } from "@/.umi/plugin-dva/connect"
import { getCart, getCart1 } from "@/service/cart"
export interface IListC{
    cartid: string,
    username: string,
    tel: number,
    proid: string,
    proname: string,
    img1: string,
    originprice: number,
    discount: number,
    sales: number,
    stock: number,
    category: string,
    brand: string,
}
export interface IListC1{
    tel:string,
    data:{
        cartid: string,
        username: string,
        tel: number,
        proid: string,
        proname: string,
        img1: string,
        originprice: number,
        discount: number,
        sales: number,
        stock: number,
        category: string,
        brand: string,
    }
}
export interface ICart{
    namespace: 'cart',
    state:{
        cartList:Array<IListC>
        cartList1:Array<IListC>
    },
    effects:{
        getCartW: Effect
        getCartW1: Effect
    },
    reducers:{
        UPDATA_CART: ImmerReducer
        UPDATA_CART1: ImmerReducer
    }
}
const GetCartList:ICart = {
    namespace: 'cart',
    state: {
        cartList: [],
        cartList1: []
    },
    effects:{
        *getCartW({payload},{call,put}){
            const res = yield call(getCart,payload)
            yield put({
                type: 'UPDATA_CART',
                payload:res.data
            })
        },
        *getCartW1({payload},{call,put}){
            const res = yield call(getCart1,payload)
            yield put({
                type: 'UPDATA_CART1',
                payload:res.data
            })
        },
    },
    reducers:{
        UPDATA_CART(state,action){
            state.cartList = action.payload
            // console.log(state.cartList,123);
        },
        UPDATA_CART1(state,action){
            state.cartList1 = action.payload
            // console.log(state.cartList1,123);
        }
    }
}

export default GetCartList